package com.hjx.servlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class LogoutServlet extends HttpServlet {
    private HttpSession session=null;
    private ServletContext context=null;
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        session=req.getSession();
        context=req.getServletContext();
        if(session.getAttribute("user")!=null && session.getAttribute("user")!=""){
//            移除改用户
            session.removeAttribute("user");
            resp.sendRedirect("/super/LoginValidate/login.jsp");
        }else{
            System.out.println("session中没有key=user的用户");
            resp.sendRedirect("/super/LoginValidate/login.jsp");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
